<?php
    session_start();
                if(!isset($_SESSION["userlogin"]) || $_SESSION["vaitro"]!="Quản Trị"){
                $_SESSION['thongbao']= "Bạn vui lòng đăng nhập theo đúng quy trình. Xin cám ơn!";
                header("location:../index.php");
                }     
?>
<html>
    <head>
        <title>Đề án</title>
        <meta http-equiv="content-type" content="text/html; charset = utf-8" />
        <link rel="stylesheet" type="text/css" href="../style.css" />
        <script lang="javascript">
            
        </script>

    </head>
    <body>
    <div id="wrap">
    
        <?php

	       include "../include/header.php";
           include "../include/mod_menu_admin.php";

        ?>
        <div id="content">
            <div id="colleft">
                <?php
                    $trang="dean";
                    include "../include/mod_idbox.php";
                    include "../include/mod_chucnang.php";
                    include "../include/mod_thongbao.php";
                    
                ?>
            </div>
                
            <div id="colright">
                <div class="tableinfo">
                    <div class="tableHeader">
                    <p>Phân Công Đề Án</p>
                    </div>
            <table border ="0" cellspacing ="0" cellpadding ="0">   <tr><td>     
                <?php
            $madean = $_POST['chondeanpc']; 
           $thoigiandean = $_POST['thoigiandean'];
           $ghichutxt = $_POST['ghichutxt'];
           if(!isset($_POST['idnhanvien'])){
                echo "
                        <script>
                            alert ('Bạn chưa chọn nhân viên!');
                            window.location = '../admin/phancong.php';
                        </script>
                        
                     ";
           }
           
           foreach ($_POST['idnhanvien'] as $idnhanvien){
            
            $dem = 0;
            //lệnh truy van kiem tra
            $sql_kiemtra = "select * from phancong where id_nhanvien = '$idnhanvien' and MaDA= $madean";
            $kiemtrapc = executeQuery($sql_kiemtra);
            $sodong=mysql_num_rows($kiemtrapc);
                if($sodong==0){
                    $sql_phancong = "INSERT INTO  `quanlydean`.`phancong` (`id_NhanVien` ,`MaDA` ,`ThoiGian` ,`GhiChu`) VALUES ('$idnhanvien',  $madean, '$thoigiandean' , '$ghichutxt')";
                    //echo $sql_phancong;
                    executeQuery($sql_phancong);
                    echo "Đã phân công cho id".$idnhanvien;echo("<br>") ;                      
                }else{
                    //$loi_phancong[] = $idnhanvien;
                    //echo $loi_phancong['$dem'];
                    //echo("<br>");
                    echo $idnhanvien. " nhân viên này đã được phân công." ;
                    echo "<br>"; 
                }
            $dem++;
            //echo $sql_kiemtra; echo("<br>");
            //echo $sodong;    
            //echo $sql_phancong; echo("<br>");
           }
                     
                        
                ?>
                </td></tr>
            </table>    
            </div>
            <?php
            include "../include/mod_chondean.php" ;
            ?>
            </div>
            <div class="clear"></div>
        </div><!--end content-->
            <?php
                include "../include/footer.php";
                
            ?>
        
    </div><!--end wrap-->        
    </body>
</html>